{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from pandas import DataFrame,Series\n",
    "import pandas as pd\n",
    "import numpy as np\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "outputs": [
    {
     "data": {
      "text/plain": "     0   1   2\n0   96  90   1\n1   12  21  91\n2   43  87  90\n3   66  13  40\n4   48  43  32\n5   29   8  92\n6   23  58  22\n7   55  54  78\n8    9   6  24\n9   40  92  14\n10  79  39  78\n11  22  60  42\n12  12  77  61\n13  59  28  37\n14  55   6  84\n15  39  12  73\n16  47  39  82\n17  25  50  79\n18  55  35  42\n19  78  82  72",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>0</th>\n      <th>1</th>\n      <th>2</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>96</td>\n      <td>90</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>12</td>\n      <td>21</td>\n      <td>91</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>43</td>\n      <td>87</td>\n      <td>90</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>66</td>\n      <td>13</td>\n      <td>40</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>48</td>\n      <td>43</td>\n      <td>32</td>\n    </tr>\n    <tr>\n      <th>5</th>\n      <td>29</td>\n      <td>8</td>\n      <td>92</td>\n    </tr>\n    <tr>\n      <th>6</th>\n      <td>23</td>\n      <td>58</td>\n      <td>22</td>\n    </tr>\n    <tr>\n      <th>7</th>\n      <td>55</td>\n      <td>54</td>\n      <td>78</td>\n    </tr>\n    <tr>\n      <th>8</th>\n      <td>9</td>\n      <td>6</td>\n      <td>24</td>\n    </tr>\n    <tr>\n      <th>9</th>\n      <td>40</td>\n      <td>92</td>\n      <td>14</td>\n    </tr>\n    <tr>\n      <th>10</th>\n      <td>79</td>\n      <td>39</td>\n      <td>78</td>\n    </tr>\n    <tr>\n      <th>11</th>\n      <td>22</td>\n      <td>60</td>\n      <td>42</td>\n    </tr>\n    <tr>\n      <th>12</th>\n      <td>12</td>\n      <td>77</td>\n      <td>61</td>\n    </tr>\n    <tr>\n      <th>13</th>\n      <td>59</td>\n      <td>28</td>\n      <td>37</td>\n    </tr>\n    <tr>\n      <th>14</th>\n      <td>55</td>\n      <td>6</td>\n      <td>84</td>\n    </tr>\n    <tr>\n      <th>15</th>\n      <td>39</td>\n      <td>12</td>\n      <td>73</td>\n    </tr>\n    <tr>\n      <th>16</th>\n      <td>47</td>\n      <td>39</td>\n      <td>82</td>\n    </tr>\n    <tr>\n      <th>17</th>\n      <td>25</td>\n      <td>50</td>\n      <td>79</td>\n    </tr>\n    <tr>\n      <th>18</th>\n      <td>55</td>\n      <td>35</td>\n      <td>42</td>\n    </tr>\n    <tr>\n      <th>19</th>\n      <td>78</td>\n      <td>82</td>\n      <td>72</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(data=np.random.randint(0,100,size = (20,3)))\n",
    "df"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "outputs": [
    {
     "data": {
      "text/plain": "55    3\n12    2\n96    1\n79    1\n25    1\n47    1\n39    1\n59    1\n22    1\n9     1\n40    1\n23    1\n29    1\n48    1\n66    1\n43    1\n78    1\nName: 0, dtype: int64"
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.max()\n",
    "df.min()\n",
    "df.std()\n",
    "df.median() # 中位数\n",
    "df.count()\n",
    "df.mean()\n",
    "df.var()\n",
    "df[0].value_counts() # 统计元素出现次数\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "outputs": [
    {
     "data": {
      "text/plain": "             0           1           2\n0           96          90           1\n1         1152        1890          91\n2        49536      164430        8190\n3      3269376     2137590      327600\n4    156930048    91916370    10483200\n5    256004096   735330960   964454400\n6   1593126912  -300477280  -256839680\n7   1722634240   954096064  1441341440\n8  -1676161024  1429609088   232456192\n9   1673035776 -1619950080 -1040580608\n10  -974159872  1246456320   439091200\n11    43319296  1772935168  1261961216\n12   519831552  -922945536  -329777152\n13   605290496   -72671232   683147264\n14 -1068761088  -436027392  1549795328\n15  1267990528  -937361408  1465909248\n16  -533987328  2097610752   -54525952\n17  -464781312  1801322496   -12582912\n18   206831616 -1378222080  -528482304\n19 -1047003136 -1345060864   603979776",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>0</th>\n      <th>1</th>\n      <th>2</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>96</td>\n      <td>90</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>1152</td>\n      <td>1890</td>\n      <td>91</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>49536</td>\n      <td>164430</td>\n      <td>8190</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>3269376</td>\n      <td>2137590</td>\n      <td>327600</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>156930048</td>\n      <td>91916370</td>\n      <td>10483200</td>\n    </tr>\n    <tr>\n      <th>5</th>\n      <td>256004096</td>\n      <td>735330960</td>\n      <td>964454400</td>\n    </tr>\n    <tr>\n      <th>6</th>\n      <td>1593126912</td>\n      <td>-300477280</td>\n      <td>-256839680</td>\n    </tr>\n    <tr>\n      <th>7</th>\n      <td>1722634240</td>\n      <td>954096064</td>\n      <td>1441341440</td>\n    </tr>\n    <tr>\n      <th>8</th>\n      <td>-1676161024</td>\n      <td>1429609088</td>\n      <td>232456192</td>\n    </tr>\n    <tr>\n      <th>9</th>\n      <td>1673035776</td>\n      <td>-1619950080</td>\n      <td>-1040580608</td>\n    </tr>\n    <tr>\n      <th>10</th>\n      <td>-974159872</td>\n      <td>1246456320</td>\n      <td>439091200</td>\n    </tr>\n    <tr>\n      <th>11</th>\n      <td>43319296</td>\n      <td>1772935168</td>\n      <td>1261961216</td>\n    </tr>\n    <tr>\n      <th>12</th>\n      <td>519831552</td>\n      <td>-922945536</td>\n      <td>-329777152</td>\n    </tr>\n    <tr>\n      <th>13</th>\n      <td>605290496</td>\n      <td>-72671232</td>\n      <td>683147264</td>\n    </tr>\n    <tr>\n      <th>14</th>\n      <td>-1068761088</td>\n      <td>-436027392</td>\n      <td>1549795328</td>\n    </tr>\n    <tr>\n      <th>15</th>\n      <td>1267990528</td>\n      <td>-937361408</td>\n      <td>1465909248</td>\n    </tr>\n    <tr>\n      <th>16</th>\n      <td>-533987328</td>\n      <td>2097610752</td>\n      <td>-54525952</td>\n    </tr>\n    <tr>\n      <th>17</th>\n      <td>-464781312</td>\n      <td>1801322496</td>\n      <td>-12582912</td>\n    </tr>\n    <tr>\n      <th>18</th>\n      <td>206831616</td>\n      <td>-1378222080</td>\n      <td>-528482304</td>\n    </tr>\n    <tr>\n      <th>19</th>\n      <td>-1047003136</td>\n      <td>-1345060864</td>\n      <td>603979776</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.cumsum() # 累加\n",
    "df.cumprod() # 累乘\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "#协方差和相关系数\n",
    "# 相关性：正相关 不相关，负相关"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "outputs": [
    {
     "data": {
      "text/plain": "150.73684210526307"
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df\n",
    "df[0].cov(df[1])\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "outputs": [
    {
     "data": {
      "text/plain": "          0         1         2\n0  1.000000  0.212862 -0.142788\n1  0.212862  1.000000 -0.276428\n2 -0.142788 -0.276428  1.000000",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>0</th>\n      <th>1</th>\n      <th>2</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>1.000000</td>\n      <td>0.212862</td>\n      <td>-0.142788</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>0.212862</td>\n      <td>1.000000</td>\n      <td>-0.276428</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>-0.142788</td>\n      <td>-0.276428</td>\n      <td>1.000000</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.corr()\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}